import { resolve } from "path";
import { defineConfig, externalizeDepsPlugin } from "electron-vite";
import react from "@vitejs/plugin-react";
import fs from "fs";
import fse from "fs-extra";

export default defineConfig({
  main: {
    plugins: [
      externalizeDepsPlugin(),
      {
        closeBundle() {
          // 复制 service 目录下所有 js 到 out/main/service
          fse.copySync(
            resolve("src/main/service"),
            resolve("out/main/service"),
          );
        },
      },
    ],
  },
  preload: {
    plugins: [externalizeDepsPlugin()],
  },
  renderer: {
    resolve: {
      alias: {
        "@renderer": resolve("src/renderer/src"),
      },
    },
    plugins: [react()],
  },
});
